<template>
  <el-dialog
      size="tiny"
      title="请选择学员出生日期"
      :before-close="handleClose"
      :visible.sync="visible">
      <el-form :model="form" ref="form" class="student-from">
        <el-form-item
          prop="birthday"
          :rules="[
            { required: true, message: '出生日期不能为空'}
          ]">
          <div class="center">
            <el-date-picker
              v-model="form.birthday"
              type="date"
              :picker-options="pickerOptions1"
              placeholder="选择日期">
            </el-date-picker>
          </div>
        </el-form-item>
      </el-form>
      <div class="center">
        <el-button type="primary" class="btn-block" @click="handleSave">确定</el-button>
        <p class="small tips" style="margin-top: 10px;">还未设置学员出生日期，不能查看基本身体数据哦</p>
      </div>
    </el-dialog>
</template>
<script>
export default {
  props: {
    visible: {
      Type: Boolean,
      default: false
    }
  },
  data () {
    return {
      form: {
        birthday: ''
      },
      pickerOptions1: {
        disabledDate (time) {
          return time.getTime() > Date.now()
        }
      }
    }
  },
  methods: {
    handleClose () {
      this.$refs['form'].resetFields()
      if (this.visible) {
        this.$emit('update:visible', false) // 更新父组件的状态
        this.$emit('close')
      }
    },
    handleSave () {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.$emit('savebirthday', +this.form.birthday)
        } else {
          return false
        }
      })
    }
  }
}
</script>
<style>

</style>